
<?php

/**
 * Template Name: Athlete Attendance Page
 * Description: Shows Athlete their attendance history
 *
 * @package WordPress
 * @subpackage Immersion
 * @since Immersion 1.0
 */

get_header( 'member' ); 

$hostname_CrossFit = "localhost";
$database_CrossFit = "quadnips_CF26AppsDev";
$username_CrossFit = "quadnips_26";
$password_CrossFit = "fearless";
$CrossFit = mysql_pconnect($hostname_CrossFit, $username_CrossFit, $password_CrossFit) or trigger_error(mysql_error(),E_USER_ERROR);


?>

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_Recordset1 = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_Recordset1 = $_SESSION['MM_Username'];
}
echo $colname_Recordset1;
mysql_select_db($database_CrossFit, $CrossFit);
$query_Recordset1 = sprintf("SELECT `Name`, `Email`, `FirstOfMonth`, `LastOfMonth`,  `Allotted_Classes`, `Attended_Count`,IF(`Allotted_Classes`=999,999, `Remaining_Classes`) as  `Remaining_Classes` FROM vCCRemainingClasses WHERE Email = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $CrossFit) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$colname_Recordset2 = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_Recordset2 = $_SESSION['MM_Username'];
}
mysql_select_db($database_CrossFit, $CrossFit);
$query_Recordset2 = sprintf("SELECT * FROM Members WHERE Email = %s", GetSQLValueString($colname_Recordset2, "text"));
$Recordset2 = mysql_query($query_Recordset2, $CrossFit) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);

$colname_Recordset3 = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_Recordset3 = $_SESSION['MM_Username'];
}
mysql_select_db($database_CrossFit, $CrossFit);
$query_Recordset3 = sprintf("SELECT * FROM vattendancelist WHERE Email = %s ORDER BY  `Date` DESC ", GetSQLValueString($colname_Recordset3, "text"));
$Recordset3 = mysql_query($query_Recordset3, $CrossFit) or die(mysql_error());
$row_Recordset3 = mysql_fetch_assoc($Recordset3);
$totalRows_Recordset3 = mysql_num_rows($Recordset3);

$colname_Recordset4 = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_Recordset4 = $_SESSION['MM_Username'];
}
mysql_select_db($database_CrossFit, $CrossFit);
$query_Recordset4 = sprintf("SELECT FirstOfMonth, LastOfMonth FROM vMemberBillingCycleRange WHERE Email = %s", GetSQLValueString($colname_Recordset4, "text"));
$Recordset4 = mysql_query($query_Recordset4, $CrossFit) or die(mysql_error());
$row_Recordset4 = mysql_fetch_assoc($Recordset4);
$totalRows_Recordset4 = mysql_num_rows($Recordset4);
?>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
      google.load('visualization', '1', {packages: ['table']});
    </script>
<script type="text/javascript">
    function drawVisualization() {
      // Create and populate the data table.
      var data = google.visualization.arrayToDataTable([
        [ 'Allotment', 'Attended', 'Remaining Classes'],
        <?php do { ?>
        <?php echo "[", $row_Recordset1['Allotted_Classes'],
           ",", $row_Recordset1['Attended_Count'], 
           ",", $row_Recordset1['Remaining_Classes'], "],"?>
           
        <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
        
      ]);
    
      // Create and draw the visualization.
      var visualization = new google.visualization.Table(document.getElementById('classcountlist'));
       
        
        
      
      visualization.draw(data, null, {allowHtml: true});
        
    }
    
    google.setOnLoadCallback(drawVisualization);
    
     
    </script>
    
<script type="text/javascript">
    function drawVisualization2() {
      // Create and populate the data table.
      var data = google.visualization.arrayToDataTable([
        ['Class Date', 'Class Time', 'Class Type'],
        <?php do { ?>
        <?php echo "['", $row_Recordset3['Date'],
           "','", $row_Recordset3['Class_Time'],  
           "','", $row_Recordset3['Class'], "'],"?>
           
        <?php } while ($row_Recordset3 = mysql_fetch_assoc($Recordset3)); ?>
        
      ]);
    
      // Create and draw the visualization.
      var visualization = new google.visualization.Table(document.getElementById('attendancehistory'));
       
        
      
      visualization.draw(data, null, {allowHtml: true});
        
    }
    
    google.setOnLoadCallback(drawVisualization2);
    
     
    </script>
		<div id="primary" class="full-width">
			<div id="content" role="main">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
	<header class="entry-header">
		<?php do_action( 'gpp_before_title' ); ?>
		<h1 class="entry-title"><?php the_title(); ?></h1>
			
	</header><!-- .entry-header -->
    <div class="entry-content">
    
    <h3><?php echo $row_Recordset2['Name']; ?> - <?php echo $_SESSION['MM_UserGroup'];?></h3>
    <p><h4>Class Attendance Summary for your Current Billing Cycle</h4>
    Current Billing Cycle: <?php echo $row_Recordset4['FirstOfMonth']; ?> thru <?php echo $row_Recordset4['LastOfMonth']; ?>
    <div id="classcountlist"></div></p>
    <p><h4>Class Attendance Detail</h4>
     <div id="attendancehistory"></div></p>
     
    
				
</div><!-- .entry-content -->
</article><!-- #post-<?php the_ID(); ?> -->
			</div><!-- #content -->
		</div><!-- #primary -->
<?php
mysql_free_result($Recordset1);

mysql_free_result($Recordset2);

mysql_free_result($Recordset3);

mysql_free_result($Recordset4);
?>

<?php get_footer(); ?>